﻿// JScript 文件


//填充县级行政单位列表
function fillCountySelect(event)
{
    $("#sltCounty").empty();
    var ProvinceId = $("#sltProvince").val();//.attr("selectedIndex");// event.data.ProvinceIndex;
    var ProvinceName = "全省（市、区）";
    if(typeof(ProvinceId) == "undefined") ProvinceId = "1";
    
    var strUrl = "Services/getDistrictList.aspx";
    $.get(strUrl,{ DISTID:ProvinceId,
                    TEMP:Math.random()
                  },
                  function(data){
                      var xmlDocument = data.documentElement;
                      var nodes = xmlDocument.getElementsByTagName("District");
                      var nCountys = nodes.length;//xmlDocument.childNodes.length;

                      var countyOptionText = new Array();
                      var countyOptionValue = new Array();
                      countyOptionValue[0] = ProvinceId;
                      countyOptionText[0] = ProvinceName
                      for(var i=0; i<nCountys; i++)
                      {
                          countyOptionValue[i+1] = nodes[i].attributes[0].nodeValue;
                          countyOptionText[i+1] = nodes[i].attributes[1].nodeValue;
//                        countyOptionValue[i] = xmlDocument.childNodes[i-1].attributes[0].nodeValue;
//                        countyOptionText[i] = xmlDocument.childNodes[i-1].attributes[1].nodeValue;
                      }
                      var countyOptions  = createOptions(countyOptionValue,countyOptionText);
                      for(var i = 0; i < nCountys + 1; i++)
                      {
                          document.getElementById("sltCounty").options.add(countyOptions[i]);
                      }
                  });

}

//计算植被指数
//function calculateRSIndex(event)
function calculateRSIndex()
{
//    var strSamplePointFileName = $("#samplePointFile").val();
//    
//    if (strSamplePointFileName.length == 0) {alert("请您选择样点文件！");return;}

    //var imageId = event.data.fileName;
    var imageId = $("#ImageListSelect").val();
    var blockSize = $("#BlockSizeSelect").val();
    showWaitImage();
    
//     var request = createRequest(); 
//     var strURL = "services/getRSIndex.aspx?filename=" + imageId;

     var strURL = "services/getRSIndex.aspx";
     $.get(strURL,{ IMAGEID:imageId,
                    BLOCKSIZE:blockSize,
                    TMP:Math.random()
                  },
                  function(data){ 
         var xmlDocument = data.documentElement;
         //alert(xmlDocument.childNodes[0].nodeValue);
         var pointNumber = xmlDocument.childNodes.length;
         
         if (pointNumber == 1){
            alert("遥感指数计算过程出错，请您检查网络连接或者重新计算！");
            return;
         }
         else
         {
             markerSampleRSPoints(xmlDocument);
             
//             var dataFileNameArray = dataUrl.split('\\');
//             var len = dataFileNameArray.length;
//             var dataFileName = dataFileNameArray[len -1];
//             
//             $("#RSIndexXml").val(dataFileName);
//             
//             loadRSIndexTable(dataFileName);
         }
     
     
     });
     //hideWaitImage();

}

//计算自定义植被指数
function calculateCustomRSIndex()
{
    var imageId = $("#ImageListSelect").val();
    var blockSize = $("#BlockSizeSelect").val();
    var formula = $("#CustomIndexText").val();
    var bandList = $("#BandListText").val();
    showWaitImage();
    
//     var request = createRequest(); 
//     var strURL = "services/getRSIndex.aspx?filename=" + imageId;

     var strURL = "services/getCustomRSIndex.aspx";
     $.get(strURL,{ IMAGEID:imageId,
                    BLOCKSIZE:blockSize,
                    FORMULA:formula,
                    BANDLIST:bandList,
                    TMP:Math.random()
                  },
                  function(data){ 
         var xmlDocument = data.documentElement;
         //alert(xmlDocument.childNodes[0].nodeValue);
         var pointNumber = xmlDocument.childNodes.length;
         
         if (pointNumber == 1){
            alert("遥感指数计算过程出错，请您检查网络连接或者重新计算！");
            return;
         }
         else
         {
             markerCoustomSamplePoint(xmlDocument);

         }
     
     
     });
}






//计算单产模块的植被指数
//function calculateRSIndex(event)
function calculateRSIndexForYield()
{
    var imageId = $("#ImageListSelect").val();//选中的影像日期        
    var rootId="";
    var distId="";
    var sampDate="";
    rootId=$("#sltProvince").val();//选中的省或直辖市的编号
    distId=$("#sltCounty").val();//选中的二级城市的编号
    showWaitImage();
     var strURL = "services/getYields.aspx";
     $.get(strURL,{ IMAGEID:imageId,
                    RID:rootId,
                    DID:distId,
                    TMP:Math.random()
                  },
                  function(data){ 
         var xmlDocument = data.documentElement;         
         var pointNumber = xmlDocument.childNodes.length;
         
         if (pointNumber == 1){
            alert("植被指数计算过程出错，请您检查网络连接或者重新计算！");
            return;
         }
         else
         {
            
             markerSampleRSPointsAndYield(xmlDocument);
         }
     });
}

//提取品质趋势预报的植被指数
function calculateRSIndexForQuality()
{
    var imageId = $("#ImageListSelect").val();//选中的影像日期        
    var rootId="";
    var distId="";
    var sampDate="";
    rootId=$("#sltProvince").val();//选中的省或直辖市的编号
    distId=$("#sltCounty").val();//选中的二级城市的编号
    showWaitImage();
     var strURL = "services/getQuality.aspx";
     $.get(strURL,{ IMAGEID:imageId,
                    RID:rootId,
                    DID:distId,
                    TMP:Math.random()
                  },
                  function(data){ 
         var xmlDocument = data.documentElement;         
         var pointNumber = xmlDocument.childNodes.length;
         
         if (pointNumber == 1){
            alert("植被指数计算过程出错，请您检查网络连接或者重新计算！");
            return;
         }
         else
         {
             markerSampleRSPointsAndQuality(xmlDocument);
         }
     });
}

//提取品质监测的植被指数
function calculateRSIndexForRSQuality()
{
    var imageId=$("#ImageListSelect").val();
    var rootId="";
    var distId="";
    //var sampDate="";
    rootId=$("#sltProvince").val();
    distId=$("#sltCounty").val();
    showWaitImage();
    var strURL="services/getRSQuality.aspx";
    $.get(strURL,{IMAGEID:imageId,
                  RID:rootId,
                  DID:distId,
                  TMP:Math.random()},
                  function(data){
                    var xmlDocument = data.documentElement;
                    var pointNumber=xmlDocument.childNodes.length;
                    if(pointNumber==1)
                    {
                        alert("植被指数计算过程出错，请您检查网络连接或者重新计算！");
                        return;
                    }
                    else
                    {
                        markerSampleRSPointsAndRSQuality(xmlDocument);
                    }                  
                  });
}

//计算相关系数
//11-4日添加参数modelType，以确定要显示的列头
//selectedAgriParamList,selectedRSIndexList,modelType
//modelType:grow是长势，列头是农学参数；rs是单产，列头是单产,quality是品质预报，列头是品质指数,Rsquality为品质遥感监测，列头是品质
function calculateRelatedCoefficient()
{
    var strUrl = "Services/getCorrelationCoefficient.aspx";
    var imageId = $("#ImageListSelect").val();
    showWaitImage();
    
    var selectedAgriParamList=arguments[0];
    var selectedRSIndexList=arguments[1];
    var modelType=arguments[2];    
    
    if(arguments.length==3)
    {
            $.get(strUrl,{  IMAGEID:imageId,
                    AGRILIST:selectedAgriParamList,
                    RSLIST:selectedRSIndexList,
                    TYPE:modelType,
                    TMP:Math.random()
                 },
                 function(data){
                    var xmlDocument = data.documentElement;
                    var nodes = xmlDocument.getElementsByTagName("Rxy");
                    var CoefficientPairCount = nodes.length;//xmlDocument.childNodes.length;
                    
                    var agriArray = new Array();                    
                    var rsArray = new Array();
                    var rArray = new Array();
                    var radioArray = new Array();
                    for(var i = 0; i < CoefficientPairCount; i++)
                    {
                        agriArray[i] = document.createTextNode(nodes[i].attributes[0].nodeValue);                        
                        rsArray[i] = document.createTextNode(nodes[i].attributes[1].nodeValue);
                        rArray[i] = document.createTextNode(nodes[i].attributes[2].nodeValue);
                        radioArray[i] = document.createElement("input");
                        radioArray[i].type = "radio";
                        radioArray[i].id = nodes[i].attributes[0].nodeValue + "_" + nodes[i].attributes[1].nodeValue;
                        $(radioArray[i]).bind("click",{id: radioArray[i].id}, function(event)
                        {
                            for(var j = 0; j < CoefficientPairCount; j++)
                            {
                                $(radioArray[j]).attr("checked",false); 
            //                    $(eval("#" + radioArray[i].id)).checked = true;
                            }
                            eval($("#" + event.data.id)).attr("checked",true);
                        });
                        
                    }
                    var tableTitleNames;
                   
                    //11-4日添加----->
                    if(modelType=="grow")
                    {
                        tableTitleNames = new Array("农学参数","植被指数","相关系数","选择");
                        var tableTitles = createTextNode(tableTitleNames);
                        var tableValues = new Array(agriArray,rsArray,rArray,radioArray);
                        
                        var RTable = new DataTable(tableTitles,tableValues,2);
                        
                        var divTable = document.createElement("div");
                        divTable.className = "resultTable";
                        divTable.appendChild(RTable);
                        $("#infoTable").empty();
                        

                        document.getElementById("infoTable").appendChild(divTable);
                        document.getElementById("infoTable").style.visibility = "visible";
                        document.getElementById("DivMenuControl").style.visibility = "visible";
                        //$("#forDatacache").data("saved","grow");
                    }
                    if(modelType=="rs")
                    {
                        tableTitleNames = new Array("单产","植被指数","相关系数","选择");
                        var tableTitles = createTextNode(tableTitleNames);
                        var tableValues = new Array(agriArray,rsArray,rArray,radioArray);
                        
                        var RTable = new DataTable(tableTitles,tableValues,2);
                        
                        var divTable = document.createElement("div");
                        divTable.className = "resultTable";
                        divTable.appendChild(RTable);
                        $("#infoTable").empty();
                        

                        document.getElementById("infoTable").appendChild(divTable);
                        document.getElementById("infoTable").style.visibility = "visible";
                        document.getElementById("DivMenuControl").style.visibility = "visible";
                        
                    }
                    //<-----11-4日添加
                    
                    if(modelType=="quality"||modelType=="Rsquality")
                    {
                        if(modelType=="quality")
                        {
                            tableTitleNames = new Array("农学参数","品质指标","相关系数","选择"); 
                        }else
                        {
                            tableTitleNames = new Array("植被指数","品质指标","相关系数","选择"); 
                        }
                        
                                               
                        var tableTitles = createTextNode(tableTitleNames);
                        var tableValues = new Array(agriArray,rsArray,rArray,radioArray);                        
                        var RTable = new DataTable(tableTitles,tableValues,2);
                        
                        var divTable = document.createElement("div");
                        divTable.className = "resultTable";

                        divTable.appendChild(RTable);
                        $("#infoTable").empty();                        

                        document.getElementById("infoTable").appendChild(divTable);
                        document.getElementById("infoTable").style.visibility = "visible";
                        document.getElementById("DivMenuControl").style.visibility = "visible";                        
                    }
                    
                    
                    hideWaitImage();
                    
                });
    }
   
}

//求解模型参数
function resolveModelParam(event)
{
    var strUrl = "Services/getCorrelationCoefficient.aspx";
    var imageId = $("#ImageListSelect").val();
    
    var SelectedRadioId = "";
    var RadioArray = $("input[type = 'radio']");
    for (var i = 0; i < RadioArray.length; i++)
    {
        if($(RadioArray[i]).attr("checked") == true)
        {
            SelectedRadioId = $(RadioArray[i]).attr("id");
            if (SelectedRadioId.indexOf("_") > -1)
                break;
        }
    }
    
    if(SelectedRadioId.length == 0 || SelectedRadioId.indexOf("_") == -1)
    {
        alert("您还没有选择用于反算模型的农学参数—植被指数序列，请您在下方的表格中选取！");
        return;
        
    }
    var paramArray = SelectedRadioId.split('_');
    /*if(paramArray!=null)
    {
        for(var i=0;i<paramArray.length;i++)
        {
            var x=paramArray[i];
            if(x=="G")
            {
                paramArray[i]="G_SWIR";
            }
        }
    }*/
    
    //alert(paramArray[0]+"  "+paramArray[1]+"   "+paramArray.length);
    var strUrl ="Services/getModelParam.aspx";
    //11-14日添加，此参数传递到页面类后，用作判断当前计算的模型类型，从id为forDatacache的div中取值，使用JQuery的data()方法，存取的变量是calculateType
    var type=$("#forDatacache").data("calculateType");
//    if(type==undefined)
//    {
//        alert("type id undefined");
//        return;
//    }else
//    {
//        alert(type);
//        return;
//    }
    
    $.get(strUrl,{  IMAGEID:imageId,
                    AGRI:paramArray[0],
                    RSINDEX:paramArray[1],
                    RSINDEX1:paramArray[2],
                    TYPE:type,
                    TEMP:Math.random()
                 },function(data){
                    var xmlDocument = data.documentElement;
                    var nodes = xmlDocument.getElementsByTagName("Param");
                    
                    var ParamA_Liner = nodes[0].attributes[0].nodeValue;
                    var ParamB_Liner = nodes[0].attributes[1].nodeValue;
                    var ParamR_Liner = nodes[0].attributes[2].nodeValue;
                    var ParamA_Exp = nodes[1].attributes[0].nodeValue;
                    var ParamB_Exp = nodes[1].attributes[1].nodeValue;
                    var ParamR_Exp = nodes[1].attributes[2].nodeValue;
                    var ParamA_Log = nodes[2].attributes[0].nodeValue;
                    var ParamB_Log = nodes[2].attributes[1].nodeValue;
                    var ParamR_Log = nodes[2].attributes[2].nodeValue;
                    
                    
                    var txtModelLine = "Y = " + ParamA_Liner + "+ (" + ParamB_Liner+ ")X";
                    $("#txtLine").val(txtModelLine);
                    $("#txtLineR").val(ParamR_Liner);
                    var txtModelExp = "Y = " + ParamA_Exp + "+ (" + ParamB_Exp + ")Exp(X)";
                    $("#txtExp").val(txtModelExp);
                    $("#txtExpR").val(ParamR_Exp);
                    var txtModelLn ="Y = " + ParamA_Log + "+ (" + ParamB_Log + ")Ln(X)";
                    $("#txtLn").val(txtModelLn);
                    $("#txtLnR").val(ParamR_Log);
             });

    //$(".resultTable")
    
    
    
    
    
    
    
//    var SampleParcelsXmlLocation = "data/" + $("#RSIndexXml").val();//"data/ParcelsIndex.xml";
//    var xmlDoc = LoadXML(SampleParcelsXmlLocation);
//    var xmlDocument = xmlDoc.documentElement;
//    
//    var tableTitleNames = new Array("地块编号","纬度","经度","叶面积指数","叶片含水量","比叶重","植株总干重","NDVI","NDWI","NRI");
//    var tableTitles = new Array();
////    for(var i = 0; i < tableTitleNames.length; i++){
////        tableTitles[i] = document.createTextNode(tableTitleNames[i]);
////    }

//    var LAITotal = 0;
//    var NdviTotal = 0;
//    var NdwiTotal = 0;
//    var BiomassTotal = 0;
//    
//    var NdviTotal2 = 0;
//    var NdwiTotal2 = 0;
//    
//    var NdviExpTotle = 0;
//    var NdviExpTotle2 = 0;
//    var NdviExpLAI = 0;
//    var NdviExpBiomass = 0;
//    var NdwiExpTotle = 0;
//    var NdwiExpTotle2 = 0;
//    var NdwiExpLAI = 0;
//    var NdwiExpBiomass = 0;


//    var NdviLnTotle = 0;
//    var NdviLnTotle2 = 0;
//    var NdviLnLAI = 0;
//    var NdviLnBiomass = 0;
//    var NdwiLnTotle = 0;
//    var NdwiLnTotle2 = 0;
//    var NdwiLnLAI = 0;
//    var NdwiLnBiomass = 0;
//    
//    
//    
//    var NdviLai = 0;
//    var NdviBiomass = 0;
//    var NdwiLai = 0;
//    var NdwiBiomass = 0;
//    
//    var ParcelsNumber = xmlDocument.childNodes.length;
//    var ParcelsVaule = new Array();
//    
//    
//    for(var i = 0; i < ParcelsNumber; i++)
//    {
//        ParcelsVaule[i] = new Array();
//        
//        for (var j = 0; j < tableTitleNames.length; j++)
//        {
//            ParcelsVaule[i][j] = xmlDocument.childNodes[i].childNodes[j].nodeValue;
//            if (j == 3) LAITotal += parseFloat(ParcelsVaule[i][j]);
//            if (j == 5) BiomassTotal += parseFloat(ParcelsVaule[i][j]);
//            if (j == 6) {
//                NdviTotal += parseFloat(ParcelsVaule[i][j]);
//                NdviLai += parseFloat(ParcelsVaule[i][j]) * parseFloat(ParcelsVaule[i][3]);
//                NdviBiomass += parseFloat(ParcelsVaule[i][j]) * parseFloat(ParcelsVaule[i][5]);
//                NdviTotal2 += parseFloat(ParcelsVaule[i][j]) * parseFloat(ParcelsVaule[i][j]); 
//                
//                NdviExpTotle += Math.exp(ParcelsVaule[i][j]);
//                NdviExpTotle2 += Math.exp(2*ParcelsVaule[i][j]);
//                NdviExpLAI += Math.exp(ParcelsVaule[i][j]) * parseFloat(ParcelsVaule[i][3]);
//                NdviExpBiomass += Math.exp(ParcelsVaule[i][j]) * parseFloat(ParcelsVaule[i][5]);

//                NdviLnTotle += Math.log(ParcelsVaule[i][j]);
//                NdviLnTotle2 += Math.log(ParcelsVaule[i][j]) * Math.log(ParcelsVaule[i][j]);
//                NdviLnLAI += Math.log(ParcelsVaule[i][j]) * parseFloat(ParcelsVaule[i][3]);
//                NdviLnBiomass += Math.log(ParcelsVaule[i][j]) * parseFloat(ParcelsVaule[i][5]);
//                
//            }
//            if (j == 7) {
//                NdwiTotal += parseFloat(ParcelsVaule[i][j]);
//                NdwiLai += parseFloat(ParcelsVaule[i][j]) * parseFloat(ParcelsVaule[i][3]);
//                NdwiBiomass += parseFloat(ParcelsVaule[i][j]) * parseFloat(ParcelsVaule[i][5]);
//                NdwiTotal2 += parseFloat(ParcelsVaule[i][j]) * parseFloat(ParcelsVaule[i][j]); 
//                
//                NdwiExpTotle += Math.exp(ParcelsVaule[i][j]);
//                NdwiExpTotle2 += Math.exp(2*ParcelsVaule[i][j]);
//                NdwiExpLAI += Math.exp(ParcelsVaule[i][j]) * parseFloat(ParcelsVaule[i][3]);
//                NdwiExpBiomass += Math.exp(ParcelsVaule[i][j]) * parseFloat(ParcelsVaule[i][5]);

//                NdwiLnTotle += Math.log(ParcelsVaule[i][j]);
//                NdwiLnTotle2 += Math.log(ParcelsVaule[i][j]) * Math.log(ParcelsVaule[i][j]);
//                NdwiLnLAI += Math.log(ParcelsVaule[i][j]) * parseFloat(ParcelsVaule[i][3]);
//                NdwiLnBiomass += Math.log(ParcelsVaule[i][j]) * parseFloat(ParcelsVaule[i][5]);

//                
//            }
//        }
//    } 
//    
//    //////////////////线性方程///////////////////////////////    
//    var aLaiNdvi = parseInt(100*(LAITotal*NdviTotal2 - NdviTotal*NdviLai)/(ParcelsNumber*NdviTotal2 - NdviTotal*NdviTotal))/100;
//    var bLaiNdvi = parseInt(100*(ParcelsNumber*NdviLai - LAITotal*NdviTotal)/(ParcelsNumber*NdviTotal2 - NdviTotal*NdviTotal))/100;
//    
//    var aBiomassNdvi = parseInt(100*(BiomassTotal*NdviTotal2 - NdviTotal*NdviBiomass)/(ParcelsNumber*NdviTotal2 - NdviTotal*NdviTotal))/100;
//    var bBiomassNdvi = parseInt(100*(ParcelsNumber*NdviBiomass - BiomassTotal*NdviTotal)/(ParcelsNumber*NdviTotal2 - NdviTotal*NdviTotal))/100;

//    var aLaiNdwi = parseInt(100*(LAITotal*NdwiTotal2 - NdwiTotal*NdwiLai)/(ParcelsNumber*NdwiTotal2 - NdwiTotal*NdwiTotal))/100;
//    var bLaiNdwi = parseInt(100*(ParcelsNumber*NdwiLai - LAITotal*NdwiTotal)/(ParcelsNumber*NdwiTotal2 - NdwiTotal*NdwiTotal))/100;

//    var aBiomassNdwi = parseInt(100*(LAITotal*NdwiTotal2 - NdwiTotal*NdwiBiomass)/(ParcelsNumber*NdwiTotal2 - NdwiTotal*NdwiTotal))/100;
//    var bBiomassNdwi = parseInt(100*(ParcelsNumber*NdwiBiomass - LAITotal*NdwiTotal)/(ParcelsNumber*NdwiTotal2 - NdwiTotal*NdwiTotal))/100;
//    /////////////////////////////////////////////////    
//    
//    
//    //////////////////指数模型///////////////////////////////    
//    var aExpLaiNdvi = parseInt(100*(LAITotal * NdviExpTotle2 - NdviExpTotle * NdviExpLAI) / (ParcelsNumber * NdviExpTotle2 - NdviExpTotle * NdviExpTotle))/100;
//    var bExpLaiNdvi = parseInt(10000*(ParcelsNumber * NdviExpLAI - NdviExpTotle * LAITotal) / (ParcelsNumber * NdviExpTotle2 - NdwiTotal*NdwiTotal))/10000;
//    //添加其他参数之间的计算方程


//    //////////////////对数模型///////////////////////////////    
//    var aLnLaiNdvi = parseInt(100*(LAITotal * NdviLnTotle2 - NdviLnTotle * NdviLnLAI) / (ParcelsNumber * NdviLnTotle2 - NdviLnTotle * NdviLnTotle))/100;
//    var bLnLaiNdvi = parseInt(10000*(ParcelsNumber * NdviLnLAI - NdviLnTotle * LAITotal) / (ParcelsNumber * NdviLnTotle2 - NdwiTotal*NdwiTotal))/10000;
//    //添加其他参数之间的计算方程
//    
//    
//    
//    if(event.data.id == 0){
//        var txtModelLine = "Y = " + aLaiNdvi + "+ (" + bLaiNdvi+ ")X";
//        $("#txtLine").val(txtModelLine);
//    }
//    else if (event.data.id == 1){
//        var txtModelExp = "Y = " + aExpLaiNdvi + "+ (" + bExpLaiNdvi + ")Exp(X)";
//        $("#txtExp").val(txtModelExp);
//    }
//    else{
//        var txtModelLn ="Y = " + aLnLaiNdvi + "+ (" + bLnLaiNdvi + ")Ln(X)";
//        $("#txtLn").val(txtModelLn);
//    }
 
}


//********************************************************灾害监测-病虫害（宫）*********************************************************************************************
//计算植被指数
//function calculateRSIndex(event)
function calculateRSIndex_disease()
{
//    var strSamplePointFileName = $("#samplePointFile").val();
//    
//    if (strSamplePointFileName.length == 0) {alert("请您选择样点文件！");return;}

    //var imageId = event.data.fileName;
    var imageId = $("#ImageListSelect").val();
    showWaitImage();
    
//     var request = createRequest(); 
//     var strURL = "services/getRSIndex.aspx?filename=" + imageId;

//调用 "services/getRSIndex.aspx"进行计算
     //var strURL = "services/getRSIndex_disease.aspx";
     var strURL = "services/getRSIndex_disease.aspx";
     $.get(strURL,{ IMAGEID:imageId,
                    TMP:Math.random()
                  },
                  function(data){ 
                  //读取xml文档
         var xmlDocument = data.documentElement;
         var nodes = xmlDocument.getElementsByTagName("Parcel");
         var pointNumber = nodes.length;
         //alert(pointNumber);
         //var pointNumber = xmlDocument.childNodes.length;
         
         if (pointNumber == 1){
            alert("植被指数计算过程出错，请您检查网络连接或者重新计算！");
            return;
         }
         else
         {
         //标注样点于图上，并显示表格
             markerSampleRSPoints_disease(xmlDocument);
             
//             var dataFileNameArray = dataUrl.split('\\');
//             var len = dataFileNameArray.length;
//             var dataFileName = dataFileNameArray[len -1];
//             
//             $("#RSIndexXml").val(dataFileName);
//             
//             loadRSIndexTable(dataFileName);
         }
     
     
     });
     //hideWaitImage();

}


//计算相关系数
function calculateRelatedCoefficient_Disease(selectedAgriParamList,selectedRSIndexList)
{
    var strUrl = "Services/getCorrelationCoefficient_Disease.aspx";
    var imageId = $("#ImageListSelect").val();
    showWaitImage();
    $.get(strUrl,{  IMAGEID:imageId,
                    AGRILIST:selectedAgriParamList,
                    RSLIST:selectedRSIndexList,
                    TMP:Math.random()
                 },
                 function(data){
                
        var xmlDocument = data.documentElement;
        var nodes = xmlDocument.getElementsByTagName("Rxy");
        var CoefficientPairCount = nodes.length;//xmlDocument.childNodes.length;
        
        var agriArray = new Array();
        var rsArray = new Array();
        var rArray = new Array();
        var radioArray = new Array();
        for(var i = 0; i < CoefficientPairCount; i++)
        {
            agriArray[i] = document.createTextNode(nodes[i].attributes[0].nodeValue);
            rsArray[i] = document.createTextNode(nodes[i].attributes[1].nodeValue);
            rArray[i] = document.createTextNode(nodes[i].attributes[2].nodeValue);
            radioArray[i] = document.createElement("input");
            radioArray[i].type = "radio";
            radioArray[i].id = nodes[i].attributes[0].nodeValue + "_" + nodes[i].attributes[1].nodeValue;
            $(radioArray[i]).bind("click",{id: radioArray[i].id}, function(event)
            {
                for(var j = 0; j < CoefficientPairCount; j++)
                {
                    $(radioArray[j]).attr("checked",false); 
//                    $(eval("#" + radioArray[i].id)).checked = true;
                }
                eval($("#" + event.data.id)).attr("checked",true);
            });
        }

        var tableTitleNames = new Array("农学参数","植被指数","相关系数","选择");
        var tableTitles = createTextNode(tableTitleNames);
        var tableValues = new Array(agriArray,rsArray,rArray,radioArray);
        
        var RTable = new DataTable(tableTitles,tableValues,2);
//        RTable.id = "RelatedCoefficientTable";
        
        var divTable = document.createElement("div");
        divTable.className = "resultTable";
        divTable.appendChild(RTable);
        $("#infoTable").empty();

        document.getElementById("infoTable").appendChild(divTable);
        document.getElementById("infoTable").style.visibility = "visible";
        document.getElementById("DivMenuControl").style.visibility = "visible";
        
        hideWaitImage();
    });
   
}

//求解模型参数
function resolveModelParam_Disease(event)
{
    var strUrl = "Services/getCorrelationCoefficient_Disease.aspx";
    var imageId = $("#ImageListSelect").val();
    
    //$(".resultTable")
    var SelectedRadioId = "";
    var RadioArray = $("input[type = 'radio']");
    for (var i = 0; i < RadioArray.length; i++)
    {
        if($(RadioArray[i]).attr("checked") == true)
        {
            SelectedRadioId = $(RadioArray[i]).attr("id");
            if (SelectedRadioId.indexOf("_") > -1)
                break;
        }
    }
    
    if(SelectedRadioId.length == 0 || SelectedRadioId.indexOf("_") == -1)
    {
        alert("您还没有选择用于反算模型的农学参数—植被指数序列，请您在下方的表格中选取！");
        return;
        
    }
    
   
    
    var paramArray = SelectedRadioId.split('_');
    
    var strUrl ="Services/getModelParam_Disease.aspx";
    $.get(strUrl,{  IMAGEID:imageId,
                    AGRI:paramArray[0],
                    RSINDEX:paramArray[1],
                    TEMP:Math.random()
                 },function(data){
                    var xmlDocument = data.documentElement;
                    var nodes = xmlDocument.getElementsByTagName("Param");
                    
                    var ParamA_Liner = nodes[0].attributes[0].nodeValue;
                    var ParamB_Liner = nodes[0].attributes[1].nodeValue;
                    var ParamR_Liner = nodes[0].attributes[2].nodeValue;
                    var ParamA_Exp = nodes[1].attributes[0].nodeValue;
                    var ParamB_Exp = nodes[1].attributes[1].nodeValue;
                    var ParamR_Exp = nodes[1].attributes[2].nodeValue;
                    var ParamA_Log = nodes[2].attributes[0].nodeValue;
                    var ParamB_Log = nodes[2].attributes[1].nodeValue;
                    var ParamR_Log = nodes[2].attributes[2].nodeValue;
                    
                    
                    var txtModelLine = "Y = " + ParamA_Liner + "+ (" + ParamB_Liner+ ")X";
                    $("#txtLine").val(txtModelLine);
                    $("#txtLineR").val(ParamR_Liner);
                    var txtModelExp = "Y = " + ParamA_Exp + "+ (" + ParamB_Exp + ")Exp(X)";
                    $("#txtExp").val(txtModelExp);
                    $("#txtExpR").val(ParamR_Exp);
                    var txtModelLn ="Y = " + ParamA_Log + "+ (" + ParamB_Log + ")Ln(X)";
                    $("#txtLn").val(txtModelLn);
                    $("#txtLnR").val(ParamR_Log);
                 });
}


//******************************************************************************************************************************************************
